package com.example.demo.demos.service;

import com.example.demo.demos.pojo.Order;
import com.example.demo.demos.utils.OrderInfo;
import com.example.demo.demos.utils.SnowflakeIdUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.util.Date;

@Service
@Transactional
public class OrderServiceImpl implements IOrderService {
    @Autowired
    private KafkaTemplate<String,Object> kafkaTemplate;
    @Override
    public OrderInfo xiadan(Order order) {

        //订单赋值 Id
        SnowflakeIdUtil snowflakeIdUtil = new SnowflakeIdUtil();
        long l = snowflakeIdUtil.nextId();
        order.setOrderId(Long.toString(l));
        //当前时间
        Date date = new Date();
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        String format = simpleDateFormat.format(date);
        order.setOrderdata(format);
        System.out.println(order);
        kafkaTemplate.send("topicname",order.toString());
        return null;
    }
}
